import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig(({mode})=>{
  const viteEnv = loadEnv(mode, process.cwd());
  const { VITE_DOMAIN_URL} = viteEnv;
  return{
  plugins: [
    vue(),
    
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  server: {
    host: 'localhost',
    port: 8888,
    open: false,
    proxy: {
      '/api': {
        target:VITE_DOMAIN_URL,
        changeOrigin: true,
        rewrite: (path) => path.replace(new RegExp('^/api'), ''),
        // secure: false,
        // configure: (proxy, options) => {
        //   // 配置此项可在响应头中看到请求的真实地址
        //   proxy.on('proxyRes', (proxyRes, req) => {
        //     proxyRes.headers['x-real-url'] = new URL(req.url || '', options.target)?.href || ''
        //   })
        // },
      },
    },
  },
}
})
